<template>
  <div class="right_side">
    <div
      v-for="item in opList"
      :key="item.id"
      class="right_side_item"
      @click="handleClick(item)"
    >
      <n-popover
        trigger="hover"
        placement="left"
        :x="100"
        raw
        arrow-class="arrow_style"
        :header-style="{ marginRight: '20px' }"
        :arrow-style="{ backgroundColor: '#1C2131', marginRight: '20px' }"
      >
        <template #trigger>
          <div class="item_wrap">
            <iconpark-icon :icon-id="item.icon" size="1rem"></iconpark-icon>
            <span>{{t (item.label) }}</span>
          </div>
        </template>
        <div class="item_wrap_info" v-if="item.id == 1">
          <div v-for="i in item.infoList" :key="i.id" @click="handleClick(i)">
            <iconpark-icon :icon-id="i.icon" size="1rem"></iconpark-icon>
            <span>{{ i.name }}</span>
          </div>
        </div>
        <div class="item_wrap_info" v-if="item.id == 2">
          <div
            v-for="i in settings.community_list"
            :key="i.name_key"
            @click="handleClick(i)"
          >
            <iconpark-icon
              :icon-id="
                i.icon == 'telegram' ? 'iconcommunity06' : 'iconcommunity04'
              "
              size="1rem"
            ></iconpark-icon>
            <span>{{ t(i.name_key) }}</span>
          </div>
        </div>
        <div class="item_qr_info" v-if="item.id == 3">
          <div class="share_img">
            <vue-qr
              id="qrid"
              text="http://43.199.35.53:8088/index.html"
              :size="200"
              logoSrc="/img/home/logo.webp"
              class="qr_code"
            ></vue-qr>
            <div class="to_do">扫描二维码</div>
          </div>
          <div class="link">
            <span>下载链接</span>
            <span class="link_info">http://pkbet down.com</span>
          </div>
        </div>
      </n-popover>
    </div>
  </div>
  <!-- 客服弹窗 -->
  <n-modal :show="kefuVisible" :mask-closable="false">
    <div>
      <ServiceModal v-model:visible="kefuVisible" />
    </div>
  </n-modal>
</template>

<script setup lang="ts">
// import { ref } from "vue";
import { User } from '@/store/user';
import ServiceModal from './ServiceModal/ServiceModal.vue';
import pinia from '@/store/index';
import { storeToRefs } from 'pinia';
import { Message } from '@/utils/discreteApi.ts';
import { Page } from '@/store/page';
import { useI18n } from 'vue-i18n';
import { handleOpenLink } from '@/utils/others';
import vueQr from 'vue-qr/src/packages/vue-qr.vue';
const userInfo = User(pinia);
const page = Page(pinia);
const { settings, serviceUrlObj } = storeToRefs(page);
const { t } = useI18n();
const {
  hasLogin,
  // roleInfo,

  kefuVisible,
  agentInfo,
} = storeToRefs(userInfo);

const opList = [
  {
    label: 'Service',
    icon: 'cebliconzd01',
    id: 1,
    infoList: [
      {
        name: 'messenge',
        icon: 'iconcommunity01',
        id: 1 - 1,
        url1: 'service_message_url',
      },
      {
        name: 'Telegram',
        icon: 'iconcommunity06',
        id: 1 - 2,
        url1: 'service_tg_url',
      },
      { name: 'Live Chat', icon: 'iconcommunity03', id: 1 - 3 },
    ],
  },
  {
    label: 'Community',
    icon: 'cebliconzd02',
    id: 2,
  },
  { label: 'mine_app_down', icon: 'cebliconzd03', id: 3 },
  { label: '', icon: 'cebliconzd04', id: 4 },
];

const handleClick = (item: any) => {
  if (item.url) {
    window.open(item.url);
    return;
  }
  switch (item.id) {
    case 1 - 3: //在线客服
      if (!hasLogin) {
        Message.error('用户未登录');
      }
      kefuVisible.value = true;
      if ([2, 4].includes(agentInfo.value.mutetype.type_id)) {
        Message.error('用户被封禁');
      } else {
        kefuVisible.value = true;
        return;
      }
      break;
    case 1 - 1:
    case 1 - 2:
      handleOpenLink(serviceUrlObj.value[item.url1]);
      break;
    case 4:
      window.scrollTo({
        top: 0,
        left: 0,
        behavior: 'smooth', // 可选，平滑滚动
      });
      break;

    default:
      break;
  }
};
</script>

<style lang="less" scoped>
.right_side {
  position: fixed;
  right: 10px;
  top: 50%;
  color: aliceblue;
  min-width: 60px;
  height: 240px;
  background: #1c2131;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  padding: 0 8px;

  .right_side_item {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 65px;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    border-bottom: 1px solid #000000;
    white-space: nowrap;

    &:last-child {
      height: 50px;
      border-bottom: unset;
    }
    .item_wrap {
      display: flex;
      flex-direction: column;
      align-items: center;
    }
  }
}
.item_wrap_info {
  color: #cecece;
  width: 177px;
  background: #1c2131;
  padding: 0 16px;
  border-radius: 8px;

  div {
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    border-bottom: 1px solid #000000;
    box-sizing: border-box;
    gap: 6px;
    cursor: pointer;

    &:last-child {
      border: unset;
    }
    span {
      font-size: 14px;
    }
  }
}
.item_qr_info {
  width: 197px;
  height: 270px;
  background: #1c2131;
  padding: 0 16px;
  border-radius: 8px;
  .link {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 5px;
    font-size: 14px;
    color: #cecece;
    .link_info {
      color: #4c9eff;
      font-size: 14px;
      cursor: pointer;
    }
  }
}
.share_img {
  position: relative;
  height: 210px;
  width: 100%;
  border-radius: 10px;
  background: linear-gradient(180deg, #1c99ff 0%, #9c1fff 100%);
  .to_do {
    color: #ffffff;
    position: absolute;
    bottom: 6px;
    width: 100%;
    text-align: center;
  }

  .qr_code {
    position: absolute;
    top: 2px;
    left: 50%;
    width: 160px;
    height: 170px;
    z-index: 100;
    border-radius: 12px;
    transform: translateX(-50%);
  }
}
</style>
